package com.copm.ifm.servers.sys.process;

import com.copm.ifm.base.basic.getter.TargetDataGetter;
import com.copm.ifm.common.process.core.emum.MsgInformTypeEnum;
import com.copm.ifm.common.process.entity.ProcessProperty;
import com.copm.ifm.common.process.entity.define.ProcessDefine;
import com.copm.ifm.servers.sys.entity.SysProject;
import com.copm.ifm.servers.sys.entity.SysStaff;
import com.copm.ifm.servers.sys.mapper.project.SysProjectMapper;
import com.copm.ifm.servers.sys.process.getter.DeptHeaderGetter;
import com.copm.ifm.servers.sys.process.getter.ProjectInfoGetter;
import com.copm.ifm.servers.sys.process.getter.SuperiorGetter;
import com.copm.ifm.servers.sys.process.service.ProcessServiceImpl;
import com.copm.ifm.servers.sys.service.staff.SysStaffService;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 流程配置类
 *
 * @author zzf
 * @date 2021/3/19 15:19
 */
//@Configuration
public class ProcessConfig {

    @Resource
    private SysStaffService staffService;

    @Resource
    private SysProjectMapper projectMapper;

    @Resource
    private SuperiorGetter superiorGetter;

    @Resource
    private DeptHeaderGetter deptHeaderGetter;

    @Bean
    public IfmProcessFactory processFactory() {

        ProcessProperty<SysStaff> processProperty = new ProcessProperty<>();
        processProperty.setUserClass(SysStaff.class)
                .setUserInfoGetter(new TargetDataGetter<>(SysStaffService::selectCurrentUserInfo, staffService))
                .setExaminePersonGetters(Arrays.asList(superiorGetter))
                .setMsgInformTypeEnum(MsgInformTypeEnum.SYSTEM);


        ProcessDefine<SysProject> projectProcessDefine = new ProcessDefine<>();
        projectProcessDefine.setName("项目流程")
                .setTargetClass(SysProject.class)
                .setTargetInfoGetter(new ProjectInfoGetter(projectMapper))
                .setEntityFieldPersonGetters(Arrays.asList(deptHeaderGetter))
                .setProcessProperty(processProperty)
        ;

        List<ProcessDefine<?>> processDefineList = new ArrayList<>();
        processDefineList.add(projectProcessDefine);


        return new IfmProcessFactory(processDefineList, new ProcessServiceImpl());
    }


}
